<template>
  <el-sub-menu v-if="menus.children.length" :index="menus.name">
    <template #title class="text-white"> {{ menus.meta.title }} </template>
    <label v-if="menus.children.length >= 1" class="label">
      <layout-menus v-for="i in menus.children" :key="i.id" :menus="i" />
    </label>
  </el-sub-menu>
  <el-menu-item v-else :index="menus.name" @click="clickMenu(menus)">
    <template #title class="text-white">{{ menus.meta.title }}</template>
  </el-menu-item>
</template>

<script>
import { defineComponent } from 'vue';
import { useRouter } from 'vue-router';

export default defineComponent({
  name: 'LayoutMenus',
  props: {
    menus: {
      type: Object,
      require: true,
      default: () => {},
    },
  },
  setup() {
    const router = useRouter();
    const clickMenu = (menu) => {
      router.push({
        path: menu.path,
        name: menu.name,
      });
    };
    return { clickMenu };
  },
});
</script>
<style scoped>
.label {
  display: block;
}
</style>
